home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Amster - Messenger
- ** by Jacob Laursen <laursen@myself.com>
- */
-
- #include "include/config.h"
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include "include/mui.h"
-
- #include <proto/dos.h>
- #include <proto/utility.h>
- #include <MUI/NListview_mcc.h>
-
- #include "include/gui.h"
- #include "include/napster.h"
- #include "include/msg.h"
- #include "amster_Cat.h"
- #include "include/protos.h"
-
- ULONG msg_new(struct IClass *cl, Object *obj, struct opSet *msg);
- MUIF MessageDisplay(REG(a2) char **array, REG(a1) struct ChatMessage *m);
- void msg_say(struct msgdata *data);
- void msg_whois(struct msgdata *data, char *info);
- void msg_whowas(struct msgdata *data, char *user, char *level, u_long lastseen);
- void InsertMsgEntry(struct msgdata *data, char *Desc, char *Msg);
-
-
- MUIF msg_dispatch(REG(a0) struct IClass *cl,REG(a2) Object *obj,REG(a1) Msg msg)
- {
- switch(msg->MethodID) {
- case OM_NEW:
- return(msg_new(cl, obj, (APTR)msg));
- case MSG_OPEN:
- set(obj, MUIA_Window_Open, TRUE);
- return(NULL);
- case MSG_GOT:
- {
- struct msgdata *data = INST_DATA(cl, obj);
- long winopen;
-
- get(obj, MUIA_Window_Open, &winopen);
- if (!winopen) set(obj, MUIA_Window_Open, TRUE);
- /* Open the window if it's not already opened, when receiving a message */
-
- msg_got(data, (char *)((muimsg)msg)->arg1, (char *)((muimsg)msg)->arg2);
- return(NULL);
- }
- case MSG_SAY:
- {
- struct msgdata *data = INST_DATA(cl,obj);
- msg_say(data);
- return(NULL);
- }
- case MSG_WHOIS:
- {
- struct msgdata *data = INST_DATA(cl,obj);
- msg_whois(data, (char *)(((muimsg)msg)->arg1));
- return(NULL);
- }
- case MSG_WHOWAS:
- {
- struct msgdata *data = INST_DATA(cl,obj);
- msg_whowas(data, (char *)(((muimsg)msg)->arg1), (char *)(((muimsg)msg)->arg2), (u_long)(((muimsg)msg)->arg3));
- return(NULL);
- }
-
- }
- return(DoSuperMethodA(cl, obj, msg));
- }
-
-
- ULONG msg_new(struct IClass *cl, Object *obj, struct opSet *msg)
- {
- static struct Hook MessageDispHook = { {NULL, NULL}, &MessageDisplay, NULL, NULL };
-
- struct msgdata *data;
- Object *msglist, *msgstr;
-
- if (obj = (Object *)DoSuperNew(cl, obj,
- MUIA_HelpNode, "messenger",
- WindowContents, VGroup,
- Child, NListviewObject,
- MUIA_NListview_NList, msglist = NListObject,
- ReadListFrame,
- MUIA_NList_Input, FALSE,
- MUIA_NList_DefaultObjectOnClick, FALSE,
- MUIA_NList_DisplayHook, &MessageDispHook,
- MUIA_NList_Format, "BAR,BAR,",
- MUIA_NList_AutoCopyToClip, TRUE,
- MUIA_NList_TypeSelect, MUIV_NList_TypeSelect_Char,
- MUIA_NList_AutoVisible, TRUE,
- End,
- End,
- Child, msgstr = StringObject,
- StringFrame,
- MUIA_CycleChain, 1,
- MUIA_String_MaxLen, 256,
- End,
- End,
- TAG_MORE, msg->ops_AttrList))
- {
- data = INST_DATA(cl, obj);
- data->msglist = msglist;
- data->msgstr = msgstr;
-
- set(obj, MUIA_Window_ID, MAKE_ID('M','E','S','G'));
- set(obj, MUIA_Window_Title, MSG_USER_TITLE),
-
- DoMethod(msgstr, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime, obj, 1, MSG_SAY);
- DoMethod(msgstr, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime, obj, 3, MUIM_Set, MUIA_Window_ActiveObject, msgstr);
- DoMethod(msgstr, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime, msgstr, 3, MUIM_Set, MUIA_String_Contents, NULL);
-
- DoMethod(obj, MUIM_Notify, MUIA_Window_Activate, TRUE, obj, 3, MUIM_Set, MUIA_Window_ActiveObject, msgstr);
- DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, obj, 3, MUIM_Set, MUIA_Window_Open, FALSE);
-
- return((ULONG)obj);
- }
- return(0);
- }
-
-
- MUIF MessageDisplay(REG(a2) char **array, REG(a1) struct ChatMessage *m)
- {
- *array++ = m->TStamp;
- *array++ = m->Nick;
- *array = m->Msg;
-
- return 0;
- }
-
-
- void msg_say(struct msgdata *data)
- {
- u_long tmp;
- char *cmd, *args;
- struct ChatMessage *m;
- char buf[32];
-
- m = malloc(sizeof(struct ChatMessage));
- if (!m) return;
-
- if (!gui_napon) {
- InsertMsgEntry(data, (char *)MSG_MESSAGE_INFO, (char *)MSG_USER_NOTCONN);
- return;
- }
- GetAttr(MUIA_String_Acknowledge, data->msgstr, &tmp);
- cmd = strtok((char *)tmp," ");
- args = strtok(NULL,"");
- if (!cmd || !args) return;
-
- if (stricmp(cmd, "/whois") == 0) {
- nap_sendbuf(NAPC_WHOIS, args);
- }
- else {
- sprintf(nap_buf, "%s %s", cmd, args);
- nap_send(NAPC_PRIVATEMSG);
-
- sprintf(buf, ">%s<", cmd);
- InsertMsgEntry(data, buf, args);
- }
- }
-
-
- void msg_whois(struct msgdata *data, char *info)
- {
- char buf[1024];
- char *nick, *level, *channels, *status, *client;
- int time, shared, downloads, uploads, link;
-
- nick = nap_token(&info);
- level = nap_token(&info);
- time = nap_ltoken(&info);
- channels = nap_token(&info);
- status = nap_token(&info);
- shared = nap_itoken(&info);
- downloads = nap_itoken(&info);
- uploads = nap_itoken(&info);
- link = nap_itoken(&info);
- client = nap_token(&info);
-
- sprintf(buf, (char *)MSG_MESSAGE_WHOIS1, nick, level, time/360, (time/60)%60, time%60, status);
- InsertMsgEntry(data, (char *)MSG_MESSAGE_WHOIS_DESC, buf);
-
- if (channels != NULL) {
- sprintf(buf, (char *)MSG_MESSAGE_WHOIS2, channels);
- InsertMsgEntry(data, (char *)MSG_MESSAGE_WHOIS_DESC, buf);
- }
-
- sprintf(buf, (char *)MSG_MESSAGE_WHOIS3,
- shared, downloads, uploads);
- InsertMsgEntry(data, (char *)MSG_MESSAGE_WHOIS_DESC, buf);
-
- sprintf(buf, (char *)MSG_MESSAGE_WHOIS4, client, nap_linktype[link]);
- InsertMsgEntry(data, (char *)MSG_MESSAGE_WHOIS_DESC, buf);
-
- set(data->msglist, MUIA_NList_First, MUIV_NList_Active_Bottom);
- }
-
-
- void msg_whowas(struct msgdata *data, char *user, char *level, u_long lastseen)
- {
- struct ClockData *cd;
- char buf[1024];
- struct ChatMessage *m;
-
- m = malloc(sizeof(struct ChatMessage));
- if (!m) return;
-
- lastseen -= (8*365+2)*24*60*60;
- /* Number of seconds between January 1st/0:00, 1970 and January 1st/0:00, 1978 */
-
- if (cd = malloc(sizeof(struct ClockData))) {
- Amiga2Date(lastseen, cd);
- sprintf(buf, (char *)MSG_MESSAGE_WHOWAS, user, level, cd->month, cd->mday, cd->year, cd->hour, cd->min, cd->sec);
- free(cd);
- InsertMsgEntry(data, (char *)MSG_MESSAGE_WHOWAS_DESC, buf);
- }
- else gui_debug("Out of memory: msg_whowas()");
- }
-
-
- void msg_got(struct msgdata *data, char *nick, char *msg)
- {
- char buf[32];
-
- sprintf(buf, "<%s>", nick);
- InsertMsgEntry(data, buf, msg);
- }
-
-
- void msg_gotwhois(char *buf)
- {
- DoMethod(gui->mwin, MSG_WHOIS, buf);
- }
-
-
- void InsertMsgEntry(struct msgdata *data, char *Desc, char *Msg)
- {
- struct ClockData *cd;
- struct DateStamp *ds, *rds;
- u_long seconds = 0;
- struct ChatMessage *m;
-
- m = malloc(sizeof(struct ChatMessage));
- if (!m) return;
-
- if (ds = malloc(sizeof(struct DateStamp))) {
- memset(ds, 0, sizeof(struct DateStamp));
- if (rds = DateStamp(ds)) {
- seconds = rds->ds_Days*24*60*60 + rds->ds_Minute*60 + rds->ds_Tick/50;
- }
- if (cd = malloc(sizeof(struct ClockData))) {
- Amiga2Date(seconds, cd);
- sprintf(m->TStamp, "%02d:%02d:%02d", cd->hour, cd->min, cd->sec);
- free(cd);
- }
- free(ds);
- }
- if (m->TStamp[0] == '\0') strcpy(m->TStamp, "[??:??:??]");
-
- m->Nick = strdup(Desc);
- m->Msg = strdup(Msg);
- DoMethod(data->msglist, MUIM_NList_InsertSingleWrap, m, MUIV_NList_Insert_Bottom, WRAPCOL2, ALIGN_LEFT);
- set(data->msglist, MUIA_NList_First, MUIV_NList_Active_Bottom);
- }
-